#include "PAP_defs.h"
#include "derivative.h"
#include "SCI_HAL_QG.h"
#include "MTIM_HAL_QG.h"
#include "Fixed_Point_Math.h"

/* Choose which data streams should be queried from the GPS */

#define GPS_GGA
//#define GPS_GLL
//#define GPS_GSA
//#define GPS_GSV
//#define GPS_RMC
#define GPS_VTG

/* GPS stream selection ends here */


/* In multiples of 8 milliseconds */
#define GPS_INITIALIZATION_WAIT 1

/* GPIO PINS DECLARATIONS */

#define GPS_VDD_PIN         PTBD_PTBD7

#define GPS_VDD_PIN_DD      PTBDD_PTBDD7

#define GPS_ENABLE_PIN      PTBD_PTBD6

#define GPS_ENABLE_PIN_DD   PTBDD_PTBDD6

/* GENERAL MACRO DECLARATIONS */

#define GPS_START_GGA_CHECKSUM  122

#define GPS_START_VTG_CHECKSUM  126

#define GPS_RX_SUCCESS 1

#define GPS_RX_FAILURE 0

#define RX_BUFFER_SIZE 80

#define GPS_VDD_ENABLE 0

#define GPS_VDD_DISABLE 1

#define GPS_ENABLED 1

#define GPS_DISABLED 0

#define GPS_PARSE_GGA 0x01

#define GPS_PARSE_VTG 0x10

#define GPS_LAT_NORTH 0xC0 

#define GPS_LAT_SOUTH 0x30

#define GPS_LONG_EAST 0x0C

#define GPS_LONG_WEST 0x03

/* DO NOT MODIFY, GPS CONFIG STRING SELECTION */
 
#ifdef GPS_GGA  
#define GPS_GGA_CONFIGURATION_STRING "$PSRF103,00,00,03,01*27" 
#else
#define GPS_GGA_CONFIGURATION_STRING "$PSRF103,00,00,00,01*24"
#endif

#ifdef GPS_GLL
#define GPS_GLL_CONFIGURATION_STRING "$PSRF103,01,00,03,01*26"
#else
#define GPS_GLL_CONFIGURATION_STRING "$PSRF103,01,00,00,01*25"
#endif

#ifdef GPS_GSA
#define GPS_GSA_CONFIGURATION_STRING "$PSRF103,02,00,03,01*25"
#else
#define GPS_GSA_CONFIGURATION_STRING "$PSRF103,02,00,00,01*26"
#endif

#ifdef GPS_GSV
#define GPS_GSV_CONFIGURATION_STRING "$PSRF103,03,00,03,01*24"
#else
#define GPS_GSV_CONFIGURATION_STRING "$PSRF103,03,00,00,01*27"
#endif

#ifdef GPS_RMC
#define GPS_RMC_CONFIGURATION_STRING "$PSRF103,04,00,03,01*23"
#else
#define GPS_RMC_CONFIGURATION_STRING "$PSRF103,04,00,00,01*20"
#endif

#ifdef GPS_VTG
#define GPS_VTG_CONFIGURATION_STRING "$PSRF103,05,00,03,01*22"
#else
#define GPS_VTG_CONFIGURATION_STRING "$PSRF103,05,00,00,01*21"
#endif

/* DO NOT MODIFY (GPS CONFIG STRING) ENDS HERE */

/* Function prototype declarations */

void vfnGPS_Init (void);

void vfnGPS_SendTermination (void);

void vfnGPS_WatchdogInit (void);

void vfnGPS_ParseBuffer (void);

void vfnGPS_ZeroCoordInit(void);